package com.gy.bearhelps.home.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gy.bearhelps.R;
import com.gy.bearhelps.home.bean.CJSJBean;
import com.gy.bearhelps.util.ListViewItemListener;

import java.util.List;

/**
 * Created by 高岳 on 2016/11/4.
 * Describe:
 */
public class DCBAdapter extends BaseAdapter {

    private Context context;
    private List<CJSJBean> list;
    private ListViewItemListener listener;

    public DCBAdapter(Context context, List<CJSJBean> list){
        this.context = context;
        this.list = list;
    }

    public void setListener(ListViewItemListener listener){
        this.listener = listener;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null){
            convertView = View.inflate(context, R.layout.adapter_dcb_layout,null);
            holder = new ViewHolder();
            holder.llMain = (LinearLayout) convertView.findViewById(R.id.adapter_cjsj_ll_main);
            holder.tvStatus = (TextView) convertView.findViewById(R.id.adapter_cjsj_tv_status);
            holder.tvTitle = (TextView) convertView.findViewById(R.id.adapter_cjsj_tv_title);
            holder.tvContent = (TextView) convertView.findViewById(R.id.adapter_cjsj_tv_content);
            holder.imgStatus = (ImageView) convertView.findViewById(R.id.adapter_cjsj_img_status);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if(position == 0){
            holder.tvStatus.setVisibility(View.VISIBLE);
            if(list.get(position).status == 0){
                holder.tvStatus.setText("未完成");
            } else {
                holder.tvStatus.setText("已完成");
            }
        } else {
            if(list.get(position).status == list.get(position - 1).status){
                holder.tvStatus.setVisibility(View.GONE);
            } else {
                holder.tvStatus.setVisibility(View.VISIBLE);
                if(list.get(position).status == 0){
                    holder.tvStatus.setText("未完成");
                } else {
                    holder.tvStatus.setText("已完成");
                }
            }
        }
        holder.tvTitle.setText(list.get(position).title+"");
        holder.tvContent.setText(list.get(position).content+"");
        if(list.get(position).status == 0){
            holder.imgStatus.setImageResource(R.mipmap.ic_check_normal);
            holder.tvTitle.setTextColor(Color.parseColor("#333333"));
        } else {
            holder.imgStatus.setImageResource(R.mipmap.ic_check_select);
            holder.tvTitle.setTextColor(Color.parseColor("#999999"));
        }

        holder.llMain.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.doPassActionListener(null,position,0,"");
            }
        });
        return convertView;
    }

    class ViewHolder{
        LinearLayout llMain;
        TextView tvStatus,tvTitle,tvContent;
        ImageView imgStatus;
    }
}
